package com.service.impl;

import com.dao.AccountDao;

import com.domain.Account01;
import com.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service("accountService")
public class AccountServiceImpl  implements AccountService {
    //自动注入
    @Autowired
    private AccountDao accountDao;


    @Override
    public Account01 findAccountByid(Integer id) {
        return  accountDao.findAccountByid(id);
    }

    @Override
    public void transfer(String sourceName, String targetName, Float money) {


        //1.根据名称查询账户转出的用户
        Account01 source=  accountDao.findAccountByName(sourceName);
        //2.根据名称查询账户转入的用户
        Account01 target=accountDao.findAccountByName(targetName);
        System.out.println(source+""+target);
        //3.转出钱
        source.setMoney(source.getMoney()-money);
         //4.转入钱
        target.setMoney(target.getMoney()+money);
        //5.更新
        //转出账户更新
        accountDao.updateAccount(source);
        //转入账户更新
        accountDao.updateAccount(target);

    }
}
